package com.yonyou.pmclouds.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;

/**
 * AbstractJobExecutor的包装器，创给xxl-job调度用，job不需要关心该类
 */
public class JobDelegate extends IJobHandler {
    private AbstractJobExecutor executor;
    private String name;

    JobDelegate(String name, AbstractJobExecutor executor) {
        this.name = name;
        this.executor = executor;
    }

    @Override
    public ReturnT<String> execute(String param) throws Exception {
        ExecResult<String> result = executor.execute(param);
        ReturnT<String> jobResult = new ReturnT<>();
        jobResult.setCode(result.getCode());
        jobResult.setContent(result.getContent());
        jobResult.setMsg(result.getMsg());
        return jobResult;
    }

    @Override
    public void init() {
        executor.init();
    }

    @Override
    public void destroy() {
        executor.destroy();
    }
}
